package com.konglz.consumer.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description
 * @Author konglz
 * @Data 2023/5/12 11:06
 */
@Configuration
public class TopicConfig {
    @Bean
    public Exchange topicExchange(){
        return ExchangeBuilder.topicExchange("demo_exchange_topic")
                .durable(true)
                .build();
    }

    @Bean
    public Queue zhangShan(){
        return QueueBuilder.durable("zhangShan").build();
    }

    @Bean
    public Queue lisi(){
        return QueueBuilder.durable("lisi").build();
    }

    @Bean
    public Binding topicBinding(@Qualifier("zhangShan") Queue zhangShan, @Qualifier("topicExchange") Exchange topicExchange){
        return BindingBuilder
                .bind(zhangShan)
                .to(topicExchange)
                .with("zhangShan.#").noargs();
    }



    @Bean
    public Binding topicBinding2(@Qualifier("lisi") Queue lisi, @Qualifier("topicExchange") Exchange topicExchange){
//        return BindingBuilder
//                .bind(lisi)
//                .to(topicExchange);


        Binding with = BindingBuilder.bind(lisi).to(topicExchange).with("lisi.#").noargs();

        return with;

    }
}
